<template>
    <div>
        <el-row class="bone-margin-10">
            <el-row style='margin-top: 10px; margin-bottom: 20px;'>
                <el-breadcrumb separator-class="el-icon-arrow-right">
                    <el-breadcrumb-item>新闻管理</el-breadcrumb-item>
                    <el-breadcrumb-item>新闻列表</el-breadcrumb-item>
                </el-breadcrumb>
            </el-row>
            <!--条件筛选-->
            <el-row :gutter="10">
                <el-col :span="3">
                    <el-select v-model.number="search.data.columnNum" clearable placeholder="请选择栏目" style="width:100%" size="small">
                        <el-option v-for='item in search.options.columns' :key='item.columnNum' :label='item.columnName' :value='item.columnNum'></el-option>
                    </el-select>
                </el-col>
                <el-col :span="3">
                    <el-select v-model.number="search.data.typeNum" clearable placeholder="请选择类型" style="width:100%" size="small">
                        <el-option v-for='item in search.options.types' :key='item.typeNum' :label='item.typeName' :value='item.typeNum'></el-option>
                    </el-select>
                </el-col>
                <el-col :span="3">
                    <el-select v-model.number="search.data.state" clearable placeholder="请选择状态" style="width:100%" size="small">
                        <el-option v-for='item in search.options.states' :key='item.stateNum' :label='item.stateName' :value='item.stateNum'></el-option>
                    </el-select>
                </el-col>
                <el-col :span="3">
                    <el-select v-model.number="search.data.carousel" clearable placeholder="是否轮播" style="width:100%" size="small">
                        <el-option v-for='item in search.options.carousels' :key='item.carouselNum' :label='item.carouselName' :value='item.carouselNum'></el-option>
                    </el-select>
                </el-col>
                <el-col :span="5">
                    <el-date-picker size="small"  v-model="search.data.dayTime" 
                    type="daterange" align="right" unlink-panels 
                    range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" 
                    :picker-options="search.options.pickerOptions"
                    value-format='yyyy-MM-dd'>
                    </el-date-picker>
                </el-col>
                <el-col :span="2" :offset="5">
                    <el-dropdown size="small" @command='createCommand'>
                        <el-button type="primary" size="small">
                            新建新闻
                            <i class="el-icon-arrow-down el-icon--right"></i>
                        </el-button>
                        <el-dropdown-menu slot="dropdown">
                            <el-dropdown-item command='0'>普通新闻</el-dropdown-item>
                            <el-dropdown-item command='1'>图集新闻</el-dropdown-item>
                            <el-dropdown-item command='3'>图文新闻</el-dropdown-item>
                            <el-dropdown-item command='4'>视频新闻</el-dropdown-item>
                            <el-dropdown-item command='5'>视频直播</el-dropdown-item>
                            <el-dropdown-item command='6'>外链新闻</el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                </el-col>

            </el-row>

            <el-row class="bone-top-10" :gutter="10">
                <el-col :span="6">
                    <el-input size="small" placeholder="搜索新闻标题,编辑,记者" suffix-icon="el-icon-search" v-model="search.data.inputKey"  @keyup.enter.native='getData'>
                    </el-input>
                </el-col>
                <el-col :span="6">
                    <el-button-group>
                        <el-button size="small" type="primary" icon="el-icon-search" @click="getData">搜索</el-button>
                        <el-button size="small" type="primary" icon="el-icon-delete" @click="clearSearch">清空</el-button>
                        <el-button size="small" type="primary" icon="el-icon-delete">导出</el-button>
                    </el-button-group>
                </el-col>
                
            </el-row>
            <!--表格
            @expand="handleExpand" 
            -->
            <el-row class="bone-top-10">
                <el-table :data="table.tabledata" border stripe style="width:100%" size="small"
                @selection-change="handleSelectionChange" 
                :highlight-current-row="true"
                @expand-change="expandChange"
                ref="multipleTable"
                v-loading="table.loading"
                >
                    <el-table-column type="selection" width="36">
                    </el-table-column>
                    <el-table-column prop="newsNum" label="编号" width="80"/>
                    <!-- 展开行 -->
                    <el-table-column type="expand">
                        <template slot-scope="props">
                            <el-form label-width="160px" size='small'>
                                <el-row>
                                    <!--新闻状态修改-->
                                    <el-col :span='6'>
                                        <el-form-item v-if='props.row.state==0' label='新闻状态[ 新创建 ]:'>
                                            <el-button-group>
                                                <el-button type="primary" @click='goExamine(props.row.newsNum)'>提交审核</el-button>
                                                <el-button type='info'>修改</el-button>
                                                <el-button type="danger">删除</el-button>
                                            </el-button-group>
                                        </el-form-item>
                                        <el-form-item v-if='props.row.state==1' label='新闻状态[ 待审核 ]:'>
                                            <el-button-group>
                                                <el-button type="primary">审核通过</el-button>
                                                <el-button type='danger'>驳回</el-button>
                                            </el-button-group>
                                        </el-form-item>
                                        <el-form-item v-if='props.row.state==2' label='新闻状态[ 待修改 ]:'>
                                            <el-button-group>
                                                <el-button type="primary">提交审核</el-button>
                                                <el-button type='info'>修改</el-button>
                                                <el-button type="danger">删除</el-button>
                                            </el-button-group>
                                        </el-form-item>
                                        <el-form-item v-if='props.row.state==3' label='新闻状态[ 审核通过 ]:'>
                                            <el-button-group>
                                                <el-button type="primary">发布</el-button>
                                                <el-button type='danger'>驳回</el-button>
                                            </el-button-group>
                                        </el-form-item>
                                        <el-form-item v-if='props.row.state==4' label='新闻状态[ 已发布 ]:'>
                                                <el-button type="danger">取消发布</el-button>
                                        </el-form-item>
                                    </el-col>

                                    <!--置顶状态-->
                                    <el-col :span='6'>
                                        <el-form-item v-if='props.row.topSort==0' label='置顶状态[ 否 ]:'>
                                            <el-button type='primary'>添加置顶</el-button>
                                        </el-form-item>
                                        <el-form-item v-else label='置顶状态[ 是 ]:'>
                                            <el-button type='danger'>取消置顶</el-button>
                                        </el-form-item>
                                    </el-col>

                                    <!--轮播状态-->
                                    <el-col :span='6'>
                                        <el-form-item v-if='props.row.carouselSort==0' label='轮播状态[ 否 ]:'>
                                            <el-button type='primary'>添加轮播</el-button>
                                        </el-form-item>
                                        <el-form-item v-else label='轮播状态[ 是 ]:'>
                                            <el-button type='danger'>取消轮播</el-button>
                                        </el-form-item>
                                    </el-col>

                                </el-row class='bone-top-10'>
                                    <!--评论状态修改-->
                                    <el-col :span='6'>
                                        <el-form-item v-if='props.row.commentType==0' label='评论状态[ 无需审核 ]:'>
                                            <el-button-group>
                                                <el-button type="primary">手动审核</el-button>
                                                <el-button type='danger'>禁止评论</el-button>
                                            </el-button-group>
                                        </el-form-item>
                                        <el-form-item v-if='props.row.commentType==1' label='评论状态[ 手动审核 ]:'>
                                            <el-button-group>
                                                <el-button type="primary">无需审核</el-button>
                                                <el-button type='danger'>禁止评论</el-button>
                                            </el-button-group>
                                        </el-form-item>
                                        <el-form-item v-if='props.row.commentType==2' label='评论状态[ 禁止评论 ]:'>
                                            <el-button-group>
                                                <el-button type="primary">无需审核</el-button>
                                                <el-button type='primary'>手动审核</el-button>
                                            </el-button-group>
                                        </el-form-item>
                                    </el-col>

                                    <!--推送状态-->
                                    <el-col :span='6'>
                                        <el-form-item v-if='props.row.pushState==0' label='推送状态[ 未推送 ]:'>
                                            <el-button type='primary'>推送</el-button>
                                        </el-form-item>
                                        <el-form-item v-else label='推送状态[ 已推送 ]:'>
                                            <el-button type='primary' disabled>已推送</el-button>
                                        </el-form-item>
                                    </el-col>
                                <el-row>

                                </el-row>
                            </el-form>
                        </template>
                    </el-table-column>
                    <el-table-column prop="title" label="标题" min-width="250" :show-overflow-tooltip="true">
                        <template slot-scope='scope'>
                            <a style="text-decoration:none" javascript='void(0);' @click='showDetail(scope.row.newsNum)' target='_blank'>{{scope.row.title}}</a>
                        </template>
                    </el-table-column>
                    <el-table-column prop="columnName" label="栏目" width="120"/>
                    <el-table-column prop="editorName" label="编辑" width="120"/>
                    <el-table-column prop="reporterName" label="记者" width="120"/>
                    <el-table-column prop="type" label="类型" width="130">
                        <template slot-scope="scope">
                            <el-tag v-if='scope.row.type==0'>普通新闻</el-tag>
                            <el-tag v-if='scope.row.type==1' type='info'>图集新闻</el-tag>
                            <el-tag v-if='scope.row.type==2' type='danger'></el-tag>
                            <el-tag v-if='scope.row.type==3' type='warning'>图文直播</el-tag>
                            <el-tag v-if='scope.row.type==4' type='success'>视频新闻</el-tag>
                            <el-tag v-if='scope.row.type==5' type='success'>视频直播</el-tag>
                            <el-tag v-if='scope.row.type==6' type='success'>外链新闻</el-tag>
                            <!--专题-->
                            <i class="el-icon-star-off" v-if='scope.row.subjectEntrance>0'></i>
                        </template>
                    </el-table-column>
                    <!-- :formatter="stateFormatter" -->
                    <el-table-column prop="state" label="状态" width="150" >
                        <template slot-scope="scope">
                            <el-tag v-if='scope.row.state==0'>新创建</el-tag>
                            <el-tag v-if='scope.row.state==1' type='info'>待审核</el-tag>
                            <el-tag v-if='scope.row.state==2' type='danger'>待修改</el-tag>
                            <el-tag v-if='scope.row.state==3' type='warning'>审核通过</el-tag>
                            <el-tag v-if='scope.row.state==4' type='success'>已发布</el-tag>

                            <!--置顶,轮播,推送等状态-->
                            <!--置顶-->
                            <i class="el-icon-upload2" v-if='scope.row.topSort>0'></i>
                            <!--轮播-->
                            <i class="el-icon-picture" v-if='scope.row.carouselSort>0'></i>
                            <!--推送-->
                            <i class="el-icon-bell" v-if='scope.row.pushState>0'></i>
                            
                        </template>
                    </el-table-column>
                    <el-table-column prop="createTime" label="时间" width="160"/>
                    <el-table-column prop="realClickNum" label="点击量" width="150"/>
                    <el-table-column prop="comment" label="评论" width="150">
                        <template slot-scope="scope">
                            <!--评论状态-->
                            <!--无需审核-->
                            <i class="el-icon-check" v-if='scope.row.commentType==0'></i>
                            <!--手动审核-->
                            <i class="el-icon-info" v-else-if='scope.row.commentType==1'></i>
                            <!--禁止评论-->
                            <i class="el-icon-close" v-else-if='scope.row.commentType==2'></i>
                        
                        </template>
                    </el-table-column>

                </el-table>
            </el-row>
            <!--分页-->
            <el-row class="bone-top-10">
                <el-pagination class="my-el-pagination" 
                @size-change="handleSizeChange" 
                @current-change="handleCurrentChange" 
                :current-page="this.table.currentPage" 
                :page-sizes="[10, 20, 30]" 
                :page-size="this.table.pageSize" 
                layout="total, sizes, prev, pager, next, jumper" 
                :total="this.table.rowCount">
                    </el-pagination>
            </el-row>
                
        </el-row>
    </div>
</template>
<script>
import Http from "@/components/utils/httpUtil";
export default {
  data() {
    return {
      search: {
        data: {
          columnNum: "",
          typeNum: "",
          state: "",
          carousel: "",
          dayTime: "",
          inputKey: ""
        },
        options: {
          columns: [
            {
              columnNum: 1,
              columnName: "头条"
            },
            {
              columnNum: 2,
              columnName: "热点"
            },
            {
              columnNum: 3,
              columnName: "科技"
            },
            {
              columnNum: 4,
              columnName: "体育"
            }
          ],
          types: [
            {
              typeNum: 0,
              typeName: "普通新闻"
            },
            {
              typeNum: 1,
              typeName: "图集新闻"
            },
            {
              typeNum: 2,
              typeName: "图文新闻"
            },
            {
              typeNum: 3,
              typeName: "视频新闻"
            },
            {
              typeNum: 4,
              typeName: "视频直播"
            },
            {
              typeNum: 5,
              typeName: "外链新闻"
            }
          ],
          states: [
            {
              stateNum: 0,
              stateName: "新创建"
            },
            {
              stateNum: 1,
              stateName: "待审核"
            },
            {
              stateNum: 2,
              stateName: "待修改"
            },
            {
              stateNum: 3,
              stateName: "审核通过"
            },
            {
              stateNum: 4,
              stateName: "已发布"
            }
          ],
          carousels: [
            {
              carouselNum: 0,
              carouselName: "非轮播"
            },
            {
              carouselNum: 1,
              carouselName: "轮播"
            }
          ],
          pickerOptions: {
            shortcuts: [
              {
                text: "最近一周",
                onClick(picker) {
                  const end = new Date();
                  const start = new Date();
                  start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                  picker.$emit("pick", [start, end]);
                }
              },
              {
                text: "最近一个月",
                onClick(picker) {
                  const end = new Date();
                  const start = new Date();
                  start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                  picker.$emit("pick", [start, end]);
                }
              },
              {
                text: "最近三个月",
                onClick(picker) {
                  const end = new Date();
                  const start = new Date();
                  start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                  picker.$emit("pick", [start, end]);
                }
              }
            ]
          }
        }
      },
      table: {
        tabledata: [],
        expandRow: "",
        currentPage: 1,
        pageSize: 10,
        rowCount: 0,
        loading: false
      }
    };
  },
  methods: {
    showDetail(newsNum) {
        window.open('https://www.baidu.com',"_blank","top=50,left=50,width=400,height=650");
    },
    createCommand(type){
        if(type=='0'){
            this.$router.push('/newsAdd');
        }
    },
    
    goExamine(newsNum) {
      this.$confirm('是否提交审核?','提示',{
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
      })
      .then(()=>{
          //做操作
          this.$message({
              type: 'success',
              message: '审核成功'
          })
      })
      .catch(()=>{
          this.$message({
              type: 'info',
              message: "失败"
          })
      })
      
    },
    handleSelectionChange() {},
    stateFormatter(row, column, cellValue) {
      if (cellValue == 0) {
        return "新创建";
      } else if (cellValue == 1) {
        return "待审核";
      } else if (cellValue == 2) {
        return "待修改";
      } else if (cellValue == 3) {
        return "审核通过";
      } else {
        return "已发布";
      }
    },
    clearSearch() {
      this.search.data.columnNum = "";
      this.search.data.typeNum = "";
      this.search.data.state = "";
      this.search.data.carousel = "";
      this.search.data.dayTime = "";
      this.search.data.inputKey = "";
      this.getData();
    },
    handleSizeChange(val) {
      this.table.pageSize = val;
      this.getData();
    },
    handleCurrentChange(val) {
      this.table.currentPage = val;
      this.getData();
    },

    //展开/关闭 行触发事件
    expandChange(row, expandedRows) {
      if (!this.table.expandRow) {
        this.table.expandRow = { ...row };
      } else {
        //上一次展开的行
        let lastRow = expandedRows.map(r => {
          if (r.newsNum == this.table.expandRow.newsNum) {
            return r;
          }
        });
        //关闭上一次展开的行
        this.$refs.multipleTable.toggleRowExpansion(lastRow[0], false);
        if (this.table.expandRow.newsNum == row.newsNum) {
          this.table.expandRow = "";
        } else {
          this.table.expandRow = { ...row };
        }
      }
    },

    getData() {
        this.table.loading = true;
      let p = {};
      p.columnNum = this.search.data.columnNum;
      p.typeNum = this.search.data.typeNum;
      p.state = this.search.data.state;
      p.carousel = this.search.data.carousel;
      if (this.search.data.dayTime) {
        let startTime = this.search.data.dayTime[0];
        let endTime = this.search.data.dayTime[1];
        if (startTime) {
          p.startTime = startTime.toString();
        }
        if (endTime) {
          p.endTime = endTime.toString();
        }
      }

      p.inputKey = this.search.data.inputKey;
      p.startNum = (this.table.currentPage - 1) * this.table.pageSize;
      p.num = this.table.pageSize;
      Http.fetch("/news/listQuery", p).then(res => {
        this.table.tabledata = res.data.rows;
        this.table.rowCount = res.data.total;
        this.table.loading = false;
      }).catch(()=>{
          this.table.loading = false;
      });
    }
  },
  mounted() {
    this.getData();
  }
};
</script>
<style scoped>

i {
    font-size: 20px;
}
/* .bone-margin-10 {
  margin: 10px 10px 10px 10px;
}

.bone-top-10 {
  margin-top: 10px;
  
} */

.el-dropdown {
  vertical-align: top;
}

.el-dropdown + .el-dropdown {
  /* margin-left: 15px; */
}

.el-icon-arrow-down {
  font-size: 12px;
}

.my-el-pagination {
  text-align: right;
}

/**展开行的padding 默认是20px 50px;*/
td .el-table__expanded-cell {
  padding: 10px 10px !important;
}
/**在 scoped 的style里面不生效*/
.el-table__expanded-cell[class*="cell"] {
  padding: 20px 20px !important;
}
</style>

<style>
.el-table__expanded-cell[class*="cell"] {
  padding: 10px 10px !important;
}
</style>

